package com.ibm.law.ui;

import java.util.List;

import org.eclipse.jface.action.MenuManager;

import com.ibm.law.domain.Resource;
import com.ibm.law.service.global.ResourceService;

public class MenuManagerFactory {
	public static MenuManager createMenuManager() {
		MenuManager menuManager = new MenuManager();
		ResourceService resourceService = new ResourceService();
		List<Resource> resources = resourceService.findRootResource();
		for (Resource resource : resources) {
			 _createMenuManager(menuManager,resource);
		}
		return menuManager;
	}

	private static void _createMenuManager(MenuManager menuManager,
			Resource resource) {
		if (resource.getChildren().size() > 0) {
			MenuManager menuManager2 = new MenuManager(resource.getName());
			menuManager.add(menuManager2);
			for (Resource child : resource.getChildren()) {
				_createMenuManager(menuManager2, child);
			}
		}
		else{
			menuManager.add(ActionFactory.getAction(resource));
		}
	}
}
